package com.xuelang.pipeline.artifact.app.harborv2;

import com.xuelang.pipeline.artifact.app.harborv2.config.HarborV2FeignConfig;
import com.xuelang.pipeline.artifact.app.harborv2.fallback.RepositoryServiceFallbackFactory;
import com.xuelang.pipeline.artifact.app.harborv2.request.ListRepositoryQuery;
import com.xuelang.pipeline.artifact.app.harborv2.response.ListRepositoryResponse;
import com.xuelang.pipeline.artifact.app.nexus3v1.xo.ApiResponseXO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * 封装Docker v2.11.0-70255684以上镜像仓库相关接口-对应repository
 *
 * @author xiwen.zxg
 * @since 2024/7/9
 */
@FeignClient(
        name = "repository-service",
        url = "${feign.rpc.harborV2Service}",
        configuration = HarborV2FeignConfig.class,
        fallbackFactory = RepositoryServiceFallbackFactory.class)
public interface RepositoryService {
    /**
     * 查询项目列表
     *
     * @param projectName
     * @param query
     * @return
     */
    @GetMapping(value = "/projects/{project_name}/repositories", produces = "application/json;charset=utf-8")
    ApiResponseXO<List<ListRepositoryResponse>> listProjectRepository(@PathVariable("project_name") String projectName, @ModelAttribute ListRepositoryQuery query);

    /**
     * 获取单个仓库信息
     *
     * @param projectName
     * @param repositoryName
     * @return
     */
    @GetMapping(value = "/projects/{project_name}/repositories/{repository_name}", produces = "application/json;charset=utf-8")
    ApiResponseXO<ListRepositoryResponse> getProjectRepository(@PathVariable("project_name") String projectName, @PathVariable("repository_name") String repositoryName);

    /**
     * 删除单个仓库信息
     *
     * @param projectName
     * @param repositoryName
     * @return
     */
    @DeleteMapping(value = "/projects/{project_name}/repositories/{repository_name}", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> deleteProjectRepository(@PathVariable("project_name") String projectName, @PathVariable("repository_name") String repositoryName);

}
